
<#include "/common/head.html"/>
    
    <table id="dg"></table>
    <div id="tb" style="padding:2px 5px;">
        <div class="wrap_search">
		            	<span class="search_item">
			            	<span class="item_text">盘点类型: </span>
			            	<span class="item_obj">
			            		<input class="easyui-combobox" name="pd_type" id="pd_type" value="" style="width:100px" data-options="
			            				valueField: 'id',
        								textField: 'text',
			            				data: [
			            					{id:'', text:'-请选择-'}<#list dictDatapd_type.keySet() as key>,{id:'${key}', text:'${dictDatapd_type.get(key)}'}</#list>
			            				]
			            			" />
			            	</span>    
			            </span>
		            	<span class="search_item">
			            	<span class="item_text">仓库编号: </span>
			            	<span class="item_obj">
			            		<input class="easyui-combobox" name="storage_no" id="storage_no" value="" style="width:100px" data-options="
			            				valueField: 'id',
        								textField: 'text',
			            				data: [
			            					{id:'', text:'-请选择-'}<#list dictDatastorage_no.keySet() as key>,{id:'${key}', text:'${dictDatastorage_no.get(key)}'}</#list>
			            				]
			            			" />
			            	</span>    
			            </span>
			            <span class="search_item">
			            	<span class="item_text">盘点状态: </span>
			            	<span class="item_obj">
			            		<input class="easyui-combobox" name="pd_status" id="pd_status" value="" style="width:100px" data-options="
			            				valueField: 'id',
        								textField: 'text',
			            				data: [
			            					{id:'', text:'-请选择-'}<#list dictDataPd_status.keySet() as key>,{id:'${key}', text:'${dictDataPd_status.get(key)}'}</#list>
			            				]
			            			" />
			            	</span>    
			            </span>
        </div>
        <div style="text-align: left; margin:6px;">
            <a href="javascript:void(0)" class="easyui-linkbutton addBtn" iconCls="glyphicon-plus" plain="true" onclick="add()">增加</a>
            <a href="javascript:void(0)" class="easyui-linkbutton updateBtn" iconCls="glyphicon-pencil" plain="true" onclick="update()">编辑</a>
            <a href="javascript:void(0)" class="easyui-linkbutton delBtn" iconCls="glyphicon-remove" plain="true" onclick="del()">删除</a> 
            <a href="javascript:void(0)" class="easyui-linkbutton exportBtn" iconCls="glyphicon-export" plain="true" onclick="exportCsv()">导出</a>|
            <a href="javascript:void(0)" class="easyui-linkbutton pankuBtn color1" iconCls="glyphicon-exclamation-sign" onclick="panDian()">盘库</a>
            <a href="javascript:void(0)" class="easyui-linkbutton detailBtn color1" iconCls="glyphicon-map-marker" plain="true" onclick="detail()">盘库单明细</a>
            <div id="searchBtnWrap" style="float:right; padding-right:5px;">
                <a href="javascript:void(0)" class="easyui-linkbutton color1" iconCls="glyphicon-search" onclick="zcurdSearch(this)">搜索</a>
                <a href="javascript:void(0)" class="easyui-linkbutton color2" iconCls="glyphicon-repeat" onclick="flushPage()">重置</a>
            </div>
        </div>
    </div>
    

<script type="text/javascript">
var datagrid = $("#dg");

var dgOptions = {
        rownumbers:true,
    	fit:true,
    	border:false,       
    	url:'listData',
    	method:'post',
    	toolbar:'#tb',
    	pageSize: 20,
    	pagination:true,
    	multiSort:true,
        queryParams: getInitParam(),
        
        columns: [[
		         {field:'id', checkbox:true}
	           	 ,{field:'pd_no', title: '盘点单号', width:150, sortable: true}
	           	 ,{field:'pd_name', title: '盘点单名', width:220, sortable: true}
	           	 ,{field:'pd_time', title: '盘点时间', width:140, sortable: true}
	           	 ,{field:'pd_user', title: '盘点人', width:120, sortable: true}
	           	 ,{field:'pd_type', title: '盘点类型', width:120, sortable: true}
	           	 ,{field:'storage_no', title: '所在仓库', width:120, sortable: true}	
	             ,{field:'pd_status', title: '盘点状态', width:80, sortable: true}
	           ]],
        rowStyler:function(index,row){
			if (row.pd_status=='未开始'){
				return 'background-color:green;color:#fff;';
			}
			}
	};
$(function() {
	handleAuthDataRule();
	datagrid.datagrid(dgOptions);
});

function zcurdSearch() {
	var param = zcurdGetParam();
	datagrid.datagrid("load", {
		queryParams: param
	})
}

function zcurdGetParam() {
	var param = {};
	$("#tb :input[name]").each(function(i, item) {
		if($(item).val()) {
			param[$(item).attr("name")] = $(item).val();	
		}
	});
	return param;
}

function getInitParam() {
	var param = {};
	$("#tb :input[name]").each(function(i, item) {
		if($(item).val()) {
			param["queryParams[" + $(item).attr("name") + "]"] = $(item).val();	
		}
	});
	return param;
}

var initPara = zcurdGetParam();
function add() {
	top.window.subPage.loadCurrDatagrid = function() {
		showMsg("增加成功！");
		datagrid.datagrid("load");
	}
	top.openWindow("盘点单主表-增加", getCurrUrl("addPage") + "?" + $.param(initPara), {size: '600x400'});
}

function update() {
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("请选择需要编辑的一条数据！");
		return;
	}
	if(rowsSel[0].pd_status=="已完成") {
		showWarnMsg("盘点已完成，不能编辑！");
		return;
	}
	var id = rowsSel[0].id;
	top.window.subPage.loadCurrDatagrid = function() {
		showMsg("更新成功！");
		datagrid.datagrid("reload");
	}
	top.openWindow("盘点单主表-编辑", getCurrUrl("updatePage") + "?id=" + id, {size: '600x400'});
}

function del() {
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("必须选择一个盘点单！");
		return;
	}
	if(rowsSel[0].pd_status=="已完成"){
		showWarnMsg("盘点已完成，不能删除！");
		return;
	}	
	confirmMsg("确认删除？", function() {
		$.post("delete", {id: rowsSel[0].id}, function(data) {
			showMsg("删除成功！");
			datagrid.datagrid("reload");
		});
	});
}

function detail() {
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("请选择需要查看的一条数据！");
		return;
	}
	var id = rowsSel[0].id;
	top.openWindow("盘点单明细查看", getCurrUrl("detailPage") + "?id=" + id, {size: '650x600'});
}

function exportCsv() {
	var option = datagrid.datagrid("options");
	var param = option.queryParams;
	param.sortName = option.sortName;
	param.sortOrder = option.sortOrder;
	window.location.href = "exportCsv?" + $.param(param);
}

function panDian() {
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("请选择一个盘库单！");
		return;
	}
	var id = rowsSel[0].id;
	var storage_no= rowsSel[0].storage_no;
	if((rowsSel[0].pd_status=="已完成")&&(rowsSel[0].pd_type=="月计划")){
		showWarnMsg("本月已盘点已完成，请不要重复盘点！");
		return;		
		}
	else if(rowsSel[0].pd_status=="已完成"){
		showWarnMsg("本次盘点已完成，请不要重复盘点！");
		return;		
	}
	else {	
	$.post("panKu",{'id':id,'storage_no':storage_no}, function(data) {	
		if(data.result=="success"){
			showMsg("盘点成功！");
			datagrid.datagrid("reload");
		}				
	});
	}
}
//按钮事件

/**
 * 打开子页
 */
var _openSubPageFlag = false;
function _openSubPage(pageUrl) {
	if(!_openSubPageFlag) {
		$("#subLayout").layout("expand", "east");
		setTimeout(function() {
			$("#subIframe").attr("src", pageUrl);
		}, 600);
		_openSubPageFlag = true;
	}else {
		$("#subIframe").attr("src", pageUrl);
	}
}
dgOptions.singleSelect=true;
//扩展js
</script>

<#include "/common/dialogWindow.html"/>
<#include "/common/foot.html"/>
